<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>大连高校环境联盟</title>
    <link rel="stylesheet" href="css/hv.css" type="text/css">
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-dialog.min.css">
    <script src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script src="js/sign-up-in.js"></script>
    <script type="text/javascript" src="js/bootstrap-dialog.min.js"></script>
    <script type="text/javascript" src="js/utils.js"></script>
     <script type="text/javascript" src="js/jquery.cookie.js"></script>
</head>

<body>
    <div style="background-color: #036eb8; height: 3px"></div>
    <div style="background-image: url('images/bg1.gif'); height: 120px;">
        <div class="container">
            <div class="container" style="padding-top: 15px">
                <img src="images/logo_title.png" alt="logo">
            </div>
        </div>
    </div>
    <div class="signUp">
        <div class="a-title">用户注册</div>
        <div class="form">
            <form>
                <div class="show-line">
                    <input type="text" id="account" name="account" placeholder="请输入自然名" onblur="checkAccount(this)" data-rule="" autocomplete="off">
                    <div class="check-result" id="statu_account">
                </div>
                </div>
                <div class="show-line">
                    <input type="text" id="email" name="email" placeholder="请输入邮箱" onblur="checkMail(this)" data-rule="" autocomplete="off">
                     <div class="check-result" id="check_mail"> </div>
                </div>
               
               
                <div class="show-line">
                    <input type="password" id="pwd1" name="pwd1" placeholder="密码长度为6-20位，支持字母、数字、横线以及下划线" onkeyup="pwd1Check()" onchange="checkPsw(this)" autocomplete="off">
                    <div class="check-result" id="statu_pwd1"> </div>
                </div>
                
                <div class="show-line">
                    <input type="password" id="pwd2" name="pwd2" placeholder="请再次输入密码" onkeyup="pwd2Check()" autocomplete="off">
                    <div class="check-result" id="statu_pwd2"></div>
                </div>
                <div class="show-line">
                    <input type="password" id="invite" name="invite" placeholder="请输入邀请码" autocomplete="off">
                    <div class="check-result" id="statu_invite">
                    </div>
                </div>
                    <div class="right_list ">
                        <a href="home.html" class="link-index">返回首页</a>
                        <button class="submit fwd_button" id="sign-up-button" type="button">注册</button>
                    </div>
            </form>
        </div>
    </div>
</body>
<script>
$(document).ready(function() {
    $('#sign-up-button').click(function() {
        var reEmail = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
        if (!reEmail.test($('#email').val())) {
            if ($('#email').val().length == 0) {
                alertWarning("邮箱不能为空")
            } else {

                alertWarning("邮箱格式有误")
            }
            return;
        }

        var Acocunt = $.trim($('#account').val());
        if (Acocunt.length == 0 || Acocunt.length > 20) {
            if (Acocunt.length == 0) {
                alertWarning("用户名不能为空")
            } else {
                alertWarning("用户名长度超过20")
            }
            return;
        }

        var rePwd = /[A-Za-z0-9\.\_]{6,12}/;
        if (!rePwd.test($('#pwd1').val())) {
            if ($('#pwd1').val().length == 0) {
                alertWarning("密码不能为空")
            } else {
                alertWarning("密码格式有误")
            }
            return;
        }
        var pwd1 = $('#pwd1').val();
        var pwd2 = $('#pwd2').val();
        if (pwd1 != pwd2) {
            alertWarning("两次密码输入不一致");
            return;
        }
        if($('#invite')=="")
        {
            alertWarning("邀请码不能为空");
            return;
        }
        $.ajax({
            type: 'post',
            url: 'user/register',
            data: {
                username: $('#account').val(),
                email: $('#email').val(),
                password: $('#pwd1').val(),
                invitationCode:$('#invite').val()
            },
            success: function(model) {
                if (model.result) {
                    alertInfoWithJump(model.message, "signup_return.html");
                } else {
                    alertWarning(model.message);
                }


            },
            fail: function() {
                alertWarning("failed");
            },
            error: function(response) {
                alertWarning("internet error");
            }
        });
        // alert("为什么要加上这一句，才能显示访问记录")
    });
})

function alertInfoWithJump(msg, url) {
    msg = "<h3 style='text-align:center;'>" + msg + "</h3>";
    BootstrapDialog.show({
        type: BootstrapDialog.TYPE_INFO,
        cssClass: 'set-dialog',
        title: "消息提示",
        message: msg,
        buttons: [{
            label: '关闭',
            action: function(dialogRef) {
                dialogRef.close();
                window.location.href = url;
            }
        }]
    });
}
</script>

</html>
